package com.oocl.aeat.redis;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.oocl.aeat.pojo.Verify;
import com.oocl.aeat.service.VerifyService;
import com.oocl.aeat.service.factory.VerifyServiceFactory;
import com.oocl.aeat.util.Const;

/**
 * 审核表缓存
 * @author GANAB
 *
 */
public class VerifyCache {
	private volatile static Map<String, Verify> cache;

	private VerifyCache() {

	}

	public static Map<String, Verify> getCache() {
		return cache;
	}

	public static void add(Verify v){
		cache.put(v.getMid(), v);
	}
	
	public static void delete(String mid){
		cache.remove(mid);
	}
	
	public static void update(Verify v) {
		if(cache.containsKey(v.getMid())){
			cache.remove(v.getMid());
			cache.put(v.getMid(), v);
		}
	}

	public static void init() {
		try {
			cache = new ConcurrentHashMap<String, Verify>();
			VerifyService service = VerifyServiceFactory.getInstance();
			List<Verify> list = service.queryAllVerify(Const.STATE_UNDO);
			if (list != null) {
				for (Verify v : list) {
					cache.put(v.getMid(), v);
				}
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
	}

	public static Verify get(String mid) {
		if (cache.containsKey(mid)) {
			return cache.get(mid);
		} else {
			return null;
		}

	}
}
